package pacman.entries.pacman.ml.features;

import pacman.game.Game;
import pacman.game.Constants.GHOST;

// returns a value between 0 and 1
// 0 means a ghost can get to the junction before pacman
// 1 means pacman can get to the junction before a ghost
public class SafeJunctionFeature extends FeatureExtractor {
	private int junction;
	public SafeJunctionFeature(float junction) {
		this.junction = (int)junction;
	}
	public float Extract(Game game) {
		int pacmanNode = game.getPacmanCurrentNodeIndex();
		int[] ghostNodes = new int[4];
		int[] ghostDistances = new int[4]; 
		for(GHOST ghost : GHOST.values()) {
			int index = ghost.ordinal();
			ghostNodes[index] = game.getGhostCurrentNodeIndex(ghost);
			ghostDistances[index] = game.getShortestPathDistance(ghostNodes[index], junction, game.getGhostLastMoveMade(ghost));
		}
		int pacmanDistance = game.getShortestPathDistance(pacmanNode, junction);
		
		for(int dist : ghostDistances) {
			if(pacmanDistance <= dist) {
				return 0.0f;
			}
		}
		return 1.0f;
	}
}